package com.sm.healthy.ui.view.ecg;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.sm.healthy.R;


/**
 *
 */
public class EcgBackgroundView extends View {


    private int XPoint = 0; // X label start point
    private int YPoint = 500; // Y label start point
    private int XLength = 720;
    private int YLength = 480;
    private float bgScale = YLength / 50; // scale for background


    int lineSize = 2;

    public EcgBackgroundView(Context context) {
        super(context);
    }

    public EcgBackgroundView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public EcgBackgroundView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawRGB(255, 255, 255);

        XLength = getMeasuredWidth();
        YPoint = (int) (getMeasuredHeight());
        YLength = YPoint;
        bgScale = (float) (YLength / 35.0); // scale for background

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setAntiAlias(true);
        paint.setStrokeWidth(lineSize);
        /**
         * draw background columns lines
         **/
        for (int i = 0; i <= XLength / bgScale; i++) {
            if (i % 5 == 0) {
            } else {
                paint.setColor(ContextCompat.getColor(getContext(), R.color.red_no_deep));
                canvas.drawLine(XPoint + i * bgScale, YPoint - YLength, XPoint + i * bgScale,
                        YPoint, paint);
            }

        }

        /**
         * draw background row lines
         **/
        for (int i = 0; i <= YLength / bgScale; i++) {
            if (i % 5 == 0) {
            } else {
                paint.setColor(ContextCompat.getColor(getContext(), R.color.red_no_deep));
                canvas.drawLine(XPoint, YPoint - YLength + i * bgScale, XPoint + XLength,
                        YPoint - YLength + i * bgScale, paint);
            }

        }

        for (int i = 0; i <= XLength / bgScale; i++) {
            if (i % 5 == 0) {
                paint.setColor(ContextCompat.getColor(getContext(), R.color.red_little_deep));
                canvas.drawLine(XPoint + i * bgScale, YPoint - YLength, XPoint + i * bgScale,
                        YPoint, paint);
            } else {

            }

        }

        for (int i = 0; i <= YLength / bgScale; i++) {
            if (i % 5 == 0) {
                paint.setColor(ContextCompat.getColor(getContext(), R.color.red_little_deep));
                canvas.drawLine(XPoint, YPoint - YLength + i * bgScale, XPoint + XLength,
                        YPoint - YLength + i * bgScale, paint);
            } else {

            }

        }
    }
}
